﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ITS.Core.Domain.News;
using ITS.DAL.News;

namespace ITS.DAL.Concrete.EF.News
{
    public class EFNewsTagRepository : INewsTagRepository
    {
        private readonly EnterpriseContext context = new EnterpriseContext();

        #region INewsTagRepository Members
        public virtual NewsTag GetNewsTagByTagID(int TagID)
        {
            return context.NewsTags.Single(x => x.TagID == TagID);
        }

        public void Delete(NewsTag tag)
        {
            context.NewsTags.Remove(tag);
            context.SaveChanges();
        }

        public IList<NewsTag> GetAllNewsTags()
        {
            return context.NewsTags.ToList();
        }

        public NewsTag GetNewsTagByName(string Name)
        {
            return context.NewsTags.SingleOrDefault(x => x.Name == Name);
        }

        public void Insert(NewsTag tag)
        {
            context.NewsTags.Add(tag);
            context.SaveChanges();
        }

        public void Update(NewsTag tag)
        {
            context.SaveChanges();
        }

        #endregion
    }
}
